package cn.com.lms.business.learning.service;

import cn.com.lms.business.learning.persistence.entity.FbLearningStudent;
import cn.com.lms.business.learning.persistence.repository.LearningStudentRepository;
import com.bnzj.core.persistence.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * LearningStudentService
 *
 * @author barry
 * @date 2020/4/8
 **/
@Service
public class LearningStudentService extends BaseService<LearningStudentRepository, FbLearningStudent, Long> {

    /**
     * 更新学生学习记录信息 (课程签出时使用)
     *
     * @param stageDetailId 阶段详情id
     * @param userId        用户id
     * @param duration      当次签到签出实际学时（单位 分钟）
     * @param finishState   学完课程标识 0否 1是
     * @param outSignTime   签出时间
     * @return
     */
    @Transactional
    public int updateUserLearningInfo(long stageDetailId, long userId, int duration, int finishState, Date outSignTime) {
        return this.repository.updateUserLearningInfo(stageDetailId, userId, duration, finishState, outSignTime);
    }

    /**
     * 获取学生阶段课程的已学习信息
     *
     * @param stageDetailId 阶段详情id
     * @param userId        用户id
     * @return
     */
    public FbLearningStudent userStageCourseLearningInfo(long stageDetailId, long userId) {
        return this.repository.userStageCourseLearningInfo(stageDetailId, userId);
    }

    public FbLearningStudent findByUserIdAndStageDetailId(Long id, Long planId) {
        return repository.findByUserIdAndStageDetailId(id, planId);
    }
}
